# Contributor: Rasmus Thomsen <oss@cogitri.dev>
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Natanael Copa <ncopa@alpinelinux.org>
# Maintainer: Pablo Correa Gómez <ablocorrea@hotmail.com>
pkgname=glib
pkgver=2.78.3
pkgrel=0
pkgdesc="Common C routines used by Gtk+ and other libs"
url="https://developer.gnome.org/glib/"
arch="all"
license="LGPL-2.1-or-later"
triggers="$pkgname.trigger=/usr/share/glib-2.0/schemas:/usr/lib/gio/modules:/usr/lib/gtk-4.0"
depends_dev="
	bzip2-dev
	docbook-xml
	docbook-xsl
	gettext-dev
	libxml2-utils
	libxslt
	python3
	"
makedepends="$depends_dev pcre2-dev meson zlib-dev libffi-dev util-linux-dev"
subpackages="
	$pkgname-dbg
	$pkgname-doc
	$pkgname-static
	$pkgname-dev
	$pkgname-lang
	$pkgname-bash-completion
	"
source="https://download.gnome.org/sources/glib/${pkgver%.*}/glib-$pkgver.tar.xz
	alwaysbash.patch
	deprecated-no-warn.patch
	"
options="!check" # don't like to be run without first being installed

# secfixes:
#   2.66.6-r0:
#     - CVE-2021-27219 GHSL-2021-045
#   2.62.5-r0:
#     - CVE-2020-6750
#   2.60.4-r0:
#     - CVE-2019-12450

build() {
	CFLAGS="$CFLAGS -ffat-lto-objects -O2" \
	CXXFLAGS="$CXXFLAGS -O2" \
	CPPFLAGS="$CPPFLAGS -O2" \
	abuild-meson \
		-Db_lto=true \
		--default-library=both \
		-Dman=true \
		-Dtests="$(want_check && echo true || echo false)" \
		. output
	meson compile -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

dev() {
	default_dev
	mkdir -p "$subpkgdir"/usr/bin "$subpkgdir"/usr/share
	find "$pkgdir"/usr/bin ! -name "glib-compile-schemas" -a \( \
		-name "gdbus-codegen" -o \
		-name "gobject-query" -o \
		-name "gresource" -o \
		-name "gtester*" -o \
		-name "glib-*" \) \
		-exec mv {} "$subpkgdir"/usr/bin \;

	amove usr/share/gdb usr/share/glib-2.0
}

static() {
	default_static
	depends="gettext-static"
}

sha512sums="
9c1af75fb973d23ce0286d5b7836eea45f9628c148ced5ac10e10abceda05024ae4c57f01439824d3287d986527500b7b959828b630b6e4a3314b5224f4d7246  glib-2.78.3.tar.xz
41d23f0797cae11d017f9e9492173f1f68125d99c28416ff2482e3eb81460a9c33cecc2bee806dad1d1da19800d0a90ae43d9a44f5e2864c2cd7c8a704669eb3  alwaysbash.patch
744239ea2afb47e15d5d0214c37d7c798edac53797ca3ac14d515aee4cc3999ef9716ba744c64c40198fb259edc922559f77c9051104a568fc8ee4fc790810b1  deprecated-no-warn.patch
"
